package com.laojiang.mapper;

import com.laojiang.pojo.Student;
import com.laojiang.pojo.Teacher;
import com.laojiang.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {
    // 用户登录
    @Select("SELECT * from user where user_name=#{user_name} and user_password=#{user_password} and user_type=#{user_type}")
    public List<User> userLogin(User user);

    // 用户注册
//    @Select("INSERT into user(user_name,user_password,user_type) values(#{user_name},#{user_password},#{user_type})")
    public int userRegister(User user);

    // 学生用户注册
    public int StudentRegister(Student student);

    // 判断用户是否已存在
    @Select("SELECT * from user where user_name=#{username}")
    public List<User> useConflict(@Param("username") String username);

    // 教师信息注册
    public int TeacherRegister(Teacher teacher);

    // 忘记密码
    public List<Student> SelStudent(@Param("studentSno") String studentSno,
                                    @Param("studentTelphone") String studentTelphone);

    // 用户登录修改
    @Update("UPDATE user set user_password=#{user_password},user_type=#{user_type} where user_name=#{user_name}\n")
    public int UpdataUser(User user);

    // 查询用户
    public List<User> SelUser(@Param("user_name") String user_name);

    // 根据用户名、密码、类型查询用户
    @Select("SELECT * from user where 1=1\n" +
            "and user_name=#{user_name} and user_password=#{user_password} and user_type=#{user_type}")
    public List<User> SelAllUser(User user);
}
